const express = require('express')
const mongoose = require('mongoose')
const bodyParser = require("body-parser")
const passport = require("passport")
const app = express()

// 数据库的链接
mongoose.set('useFindAndModify', false)
mongoose.connect("mongodb://localhost:27017/MobileUser", { useNewUrlParser: true }, () => {
    console.log("数据库连接成功");
});

// 使用 body-parser 中间件
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// passport 初始化
app.use(passport.initialize());
require("./config/passport")(passport);

// 测试
app.get("/", (req, res) => {
    res.send("helloword!");
})

// 引入 users.js
const users = require("./api/user");

// 使用 api
app.use("/api/users", users);


const port = process.env.PORT || 5000;
app.listen(port, () => {
    console.log(`当前post:${port}`);
})